<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/global/global-head.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>吉车惠后台管理系统</title>
	<%@include file="/global/global-other.jsp" %>
<script type="text/javascript">
	var $bn_oilStaion_worker_list = new Object();
	var $bn_oilStaion_worker_list_Datagrid;
	var $bn_oilStaion_worker_list_toolbar = [{
		text:'<i class="fa fa-search " aria-hidden="true"></i>查询',
		handler:function(){
			$bn_oilStaion_worker_list.reload();
		}
	},
		{
			text:'<i class="fa fa-retweet" aria-hidden="true"></i>设备绑定',
			handler:function(){
				$bn_oilStaion_worker_list.saveInit();
			}
		},
		{
			text:'<i class="fa fa-random" aria-hidden="true"></i>设备解绑',
			handler:function(){
				$bn_oilStaion_worker_list.updateInit();
			}
		}
	];
	$(function(){
		$bn_oilStaion_worker_list_Datagrid = $('#bn_oilStaionDatagrid').datagrid({
			filterBtnIconCls:'icon-filter',
			queryParams: {
//				filter_EQ_bn_device.delete_status: 0
			},
			pageSize : 20,
			remoteFilter:true
		});
		$bn_oilStaion_worker_list_Datagrid.datagrid('enableFilter', [
			{field:'deviceSn',type:'text'},
			{
				field:'deviceStatus',
				type:'combobox',
				options:{
					valueField: 'code',
					textField: 'name',
					url:'${ctx}/tcode/all/method?method=getCacheCdDeviceStatus'
				},
				op:['equal']
			},
			{field:'oilStationName',type:'text'},
			{field:'updateBy',type:'text'}
		]);

	});


	$bn_oilStaion_worker_list.test=function(a){

	}

	$bn_oilStaion_worker_list.reload = function(){
		$("#bn_oilStaionDatagrid").datagrid('reload');
	};

	var viewDialog = null;
	$bn_oilStaion_worker_list.saveInit = function(){
		var row = $bn_oilStaion_worker_list_Datagrid.datagrid('getSelected');
		if(row==null){
			$.messager.alert("提示",errMsg("请选择一行数据！"),"error");
		}
		var deviceStatus = row.deviceStatus;
		if(deviceStatus == '已绑定'){
			$.messager.alert("提示",errMsg("您选择的设备已经绑定，无法重复绑定！"),"error");
			return;
		}
		$('#saveinit').html("");
		viewDialog = parent.$.dialog({
			title: '<i class="fa fa-windows"></i><span class="dialog-title">设备绑定<span>',
			href: '${ctx}/bn/ref/insert?_m=init&deviceId='+row.deviceId+'&deviceSn='+row.deviceSn+'&r='+Math.random(),
			width: 900,
			height: 440,
			modal: true,
			onClose : function() {
				$(this).dialog('destroy');
			},
			buttons: [{
				text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;保 存',
				width:'70px',
				handler: function(){
					viewDialog.find('iframe').get(0).contentWindow.submitForm(viewDialog, $bn_oilStaion_worker_list_Datagrid);
				}
			},{
				text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;返 回',
				width:'70px',
				handler: function(){
					viewDialog.dialog('destroy');
				}
			}]
		});
	}


	$bn_oilStaion_worker_list.updateInit = function (){
		var row = $bn_oilStaion_worker_list_Datagrid.datagrid('getSelected');
		if(row==null){
			parent.$.messager.alert("提示",errMsg("请选择一行数据！"),"error");
		}else{
			var bundlingStatus = row.bundlingStatus;
			if(bundlingStatus == '未绑定'){
				$.messager.alert("提示",errMsg("您选择的用户未进行油卡绑定，无法解除绑定！"),"error");
				return;
			}
			parent.$.messager.confirm('提示','是否要解除绑定设备SN为：【'+row.deviceSn+'】，加油站为【'+row.oilStationName+'】这条记录？',function(flag){
				if (flag){
					$.post('${ctx}/bn/ref/delete?_m=exec', {deviceId : row.deviceId,oilStationId : row.oilStationId,deviceSn : row.deviceSn}, function(json) {
						if(statusMsg(json)){
							parent.$.messager.alert("提示","解除绑定成功！","info",function(){
								$bn_oilStaion_worker_list_Datagrid.datagrid('reload');
							});
						}
					}, "JSON");
				}
			});
		}
	}


</script>
	</head>
<body>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
<table id="bn_oilStaionDatagrid"  style="width:100%;height: 100%"
	   data-options="border:false,rownumbers:true,autoRowHeight:false,singleSelect:true,pagination:true,sortName:'deviceSn',sortOrder:'desc',toolbar:$bn_oilStaion_worker_list_toolbar,rowStyler: function(index,row){return {style:'height:30px'};},url:'${ctx}/bn/ref/search?_m=load',method:'post'">
	<thead>
		<tr>
			<th data-options="field:'deviceSn',width:100,align:'center'">终端设备SN</th>
			<th data-options="field:'deviceStatus',width:120,align:'center',formatter:function(value,row,index){return row.deviceStatusName;}">设备状态</th>
			<th data-options="field:'oilStationName',width:120,align:'center'">加油站</th>
			<th data-options="field:'updateBy',width:80,align:'center'">绑定人</th>
		</tr>
	</thead>
</table>
</div>
	</div>
</body>
</html>